<?php
session_start();

require './includes/functions.php';

if (!isset($_SESSION['user'])) {
    redirect_to("../401.php");
}

if (isset($_POST['id'])) {

    $id = $_POST['id'];
    $nom = $_POST['nom'];
    $prenom = $_POST['prenom'];
    $mail = $_POST['mail'];

    $tel = $_POST['tel'];
    $institution = $_POST['institution'];
    $labo = $_POST['labo'];
    $fonction = $_POST['fonction'];
    $se = $_POST['se'];
    $adresse = addslashes($_POST['adresse']);
    $premier = $_POST['premier'];
    $payement = $_POST['payement'];



    $page = "./adm_participants.php";

    $sql = "update and_participant set nom='$nom', prenom='$prenom', mail='$mail', tel='$tel', institution='$institution', labo='$labo', fonction='$fonction', se='$se', adresse='$adresse', premier='$premier', payement='$payement' where id =$id";
    $msg = "Participant modifi&eacute;";
    $msg_err = "Erreur modification du participant !!";



    require_once './includes/db.php';
    echo "<link rel=\"stylesheet\" href=\"./css/screen.css\" media=\"screen\" />";

    $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
    $mysqli->set_charset("utf8");

    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL with MySQLI: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }



    $mysqli->query($sql) or die('Problem executing update query ' . $mysqli->error);


    if ($mysqli->affected_rows > 0) {

        echo "<br /><br /><h1 style=\"color: font-family: 'PT Sans Narrow'\"><b style=\"color: yellowgreen;\">$msg</b></h1><h4>Redirection vers la page participants; dans <b><span id='compteur' class='compteur'>";
        ?>

        <script language='javascript'>

            function timestamp(t)
            {
                document.getElementById("compteur").innerHTML=(t/1000);
                t-=1000;
                if(t==0)
                    self.location="<?php echo $page; ?>";
                                                                                    		 
                setTimeout("timestamp("+t+")",1000);
            }
            window.onload = timestamp(2000);
        </script>
        <?php
        echo "</span></b> secondes</h4><img src='./adm-auth/images/superdroid.png' /></div><div class='bas' id='bas'></div>";
    } else {

        echo "<br /><br /><h1><b style=\"color: rgb(230, 0, 17);\">$msg_err</b></h1><h4>Redirection vers la page participants dans <b><span id='compteur' class='compteur'>";
        ?>

        <script language='javascript'>

            function timestamp(t)
            {
                document.getElementById("compteur").innerHTML=(t/1000);
                t-=1000;
                if(t==0)
                    self.location="<?php echo $page; ?>";
                                                                                    		 
                setTimeout("timestamp("+t+")",1000);
            }
            window.onload = timestamp(2000);
        </script>
        <?php
        echo "</span></b> secondes</h4><img src='./adm-auth/images/superdroid.png' /></div><div class='bas' id='bas'></div>";
    }

    $mysqli->close();
} else {




    if (isset($_GET['id']) && !isset($_GET['nom'])) {

        require './includes/db.php';
        echo "<link rel=\"stylesheet\" href=\"./css/screen.css\" media=\"screen\" />";

        $id = $_GET['id'];

        $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
        $mysqli->set_charset("utf8");

        if ($mysqli->connect_errno) {
            echo "Failed to connect to MySQL with MySQLI: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
        }


        $sql0 = "delete from and_accompagnants where id_participant = " . $id;
        $sql1 = "delete from and_participant where id = " . $id;

        $mysqli->query($sql0) or die('Problem deleting' . $mysqli->errno);
        $mysqli->query($sql1) or die('Problem deleting' . $mysqli->errno);


        if ($mysqli->affected_rows > 0) {

            echo "<br /><br /><h1 style=\"color: font-family: 'PT Sans Narrow'\"><b style=\"color: yellowgreen;\">Participant supprim&eacute;</b></h1><h4>Redirection vers la page participants dans <b><span id='compteur' class='compteur'>";
            ?>

            <script language='javascript'>

                function timestamp(t)
                {
                    document.getElementById("compteur").innerHTML=(t/1000);
                    t-=1000;
                    if(t==0)
                        history.back();
                                                                                                    		 
                    setTimeout("timestamp("+t+")",1000);
                }
                window.onload = timestamp(2000);
            </script>
            <?php
            echo "</span></b> secondes</h4><img src='./adm-auth/images/superdroid.png' /></div><div class='bas' id='bas'></div>";
        } else {

            echo "<br /><br /><h1><b style=\"color: rgb(230, 0, 17);\">Erreur de suppression du participant</b></h1><h4>Redirection vers la page participants dans <b><span id='compteur' class='compteur'>";
            ?>

            <script language='javascript'>

                function timestamp(t)
                {
                    document.getElementById("compteur").innerHTML=(t/1000);
                    t-=1000;
                    if(t==0)
                        history.back();
                                                                                                    		 
                    setTimeout("timestamp("+t+")",1000);
                }
                window.onload = timestamp(2000);
            </script>
            <?php
            echo "</span></b> secondes</h4><img src='./adm-auth/images/superdroid.png' /></div><div class='bas' id='bas'></div>";
        }



        $mysqli->close();
    } else {


        require_once './includes/db.php';

        if (isset($_GET['nom'])) {

            $titre = "Modifier un participant";
            $bouton = "Modifier";

            $id = $_GET['id'];
            $nom = $_GET['nom'];
            $prenom = $_GET['prenom'];
            $mail = $_GET['mail'];

            $tel = $_GET['tel'];
            $institution = $_GET['institution'];
            $labo = $_GET['labo'];
            $fonction = $_GET['fonction'];
            $se = $_GET['se'];

            $premier = $_GET['premier'];
            $payement = $_GET['payement'];

            $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
            $mysqli->set_charset("utf8");
            if ($mysqli->connect_errno) {
                echo "Failed to connect to MySQL with MySQLI: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
            }

            $sql = "select adresse from and_participant where id = $id";

            $result = $mysqli->query($sql);


            $row = $result->fetch_assoc();
            $adresse = $row['adresse'];
            $mysqli->close();
        } else {
            redirect_to("../401.php");
        }
        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en">
            <head><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW" />
                <!--

        Base template (without user's data) checked by http://validator.w3.org : "This page is valid XHTML 1.0 Transitional"
                -->
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
                <title>ISIMG Android</title>

                <link href="./css/screen.css" rel="stylesheet" media="screen" />


                <link rel="stylesheet" href="./css/style.css" type="text/css" media="screen" />
                <!--[if IE 6]><link rel="stylesheet" href="./css/style.ie6.css" type="text/css" media="screen" /><![endif]-->
                <!--[if IE 7]><link rel="stylesheet" href="./css/style.ie7.css" type="text/css" media="screen" /><![endif]-->

                <style>

                    .henislayout-cell, .heniscontent-layout-row
                    {
                        background-color: Transparent;
                        vertical-align: top;
                        text-align: left;
                        border: none;

                        padding:0;
                    }
                    .henisarticle td
                    {
                        padding: 5px;
                        border: solid 0px #616161;
                        vertical-align: top;
                        text-align: left;
                    }

                </style>






                <script type="text/javascript" src="./js/jquery.js"></script>
                <script type="text/javascript" src="./js/script.js"></script>



                <script type="text/javascript">
                                                               
                    var emailfilter=/^\w+[\+\.\w-]*@([\.\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i

                    function verif_formulaire(e)
                    {
                                
                        $("#nom").html('');
                        $("#prenom").html('');
                        $("#msg").html('');
                        $("#institution").html('');
                        $("#fonction").html('');
                        $("#tel").html('');
                        $("#mail").html('');
                                
                        var returnval=emailfilter.test(e.value)
                        if(document.formulaire.nom.value == "")  {
                            $('#nom').html("Veuillez saisir votre nom!");
                            document.formulaire.nom.focus();
                            return false;
                        }
                        if(document.formulaire.prenom.value == "") {
                            $('#prenom').html("Veuillez saisir votre prénom!");
                            document.formulaire.prenom.focus();
                            return false;
                        }
                        if (returnval==false){
                            $('#mail').html("Veuillez saisir une adresse e-mail valide.");
                            e.select();
                            return returnval;
                        }
                        if(document.formulaire.tel.value == "") {
                            $('#tel').html("Veuillez saisir votre téléphone!");
                            document.formulaire.tel.focus();
                            return false;
                        }
                        if(document.formulaire.institution.value == "") {
                            $('#institution').html("Veuillez saisir votre institution!");
                            document.formulaire.institution.focus();
                            return false;
                        }
                        if(document.formulaire.fonction.value == "") {
                            $('#fonction').html("Veuillez saisir votre fonction!");
                            document.formulaire.fonction.focus();
                            return false;
                        }
                                        
                                        
                                        
                        return true;
                                                  
                                                          
                    }

                </script>
            </head>
            <body>
                <div id="henispage-background-glare">
                    <div id="henispage-background-glare-image">
                        <div id="henismain">
                            <div class="henisheader">
                                <div class="henisheader-center">
                                    <div class="henisheader-jpeg"></div>
                                </div>
                                <div class="henisheader-wrapper">
                                    <div class="henisheader-inner">
                                        <div class="henisheaderobject"></div>
                                        <div class="henislogo">
                                            <h1 id="name-text" class="henislogo-name"><a href="./index.php">Administration du site</a></h1>
                                            <h2 id="slogan-text" class="henislogo-text">ISIMG Android</h2>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="henisnav">
                                <div class="henisnav-l"></div>
                                <div class="henisnav-r"></div>
                                <div class="henisnav-wrapper">
                                    <div class="henisnav-inner">
                                        <ul class="henismenu">
                                            <li><a href="./index.php"><span class="l"> </span><span class="r"> </span><span class="t">Accueil</span></a></li>
                                            <li><a href="./adm_actualites.php"><span class="l"> </span><span class="r"> </span><span class="t">Actualités</span></a></li>
                                            <li><a href="./adm_sponsors.php"><span class="l"> </span><span class="r"> </span><span class="t">Sponsors</span></a></li>
                                            <li><a href="./adm_comite_pilotage.php"><span class="l"> </span><span class="r"> </span><span class="t">Comité de pilotage</span></a></li>
                                            <li><a href="./adm_comite_organisation.php"><span class="l"> </span><span class="r"> </span><span class="t">Comité d'organisation</span></a></li>
                                            <li><a href="./adm_participants.php" class="active"><span class="l"> </span><span class="r"> </span><span class="t">Participants</span></a></li>
                                            <li><a href="./adm-auth/act_authentification.php?action=logout"><span class="l"> </span><span class="r"> </span><span class="t">Déconnexion</span></a></li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                            <div class="henissheet">
                                <div class="henissheet-tl"></div>
                                <div class="henissheet-tr"></div>
                                <div class="henissheet-bl"></div>
                                <div class="henissheet-br"></div>
                                <div class="henissheet-tc"></div>
                                <div class="henissheet-bc"></div>
                                <div class="henissheet-cl"></div>
                                <div class="henissheet-cr"></div>
                                <div class="henissheet-cc"></div>
                                <div class="henissheet-body">
                                    <div class="heniscontent-layout">
                                        <div class="heniscontent-layout-row">
                                            <div class="henislayout-cell heniscontent">
                                                <div class="henispost">
                                                    <div class="henispost-tl"></div>
                                                    <div class="henispost-tr"></div>
                                                    <div class="henispost-bl"></div>
                                                    <div class="henispost-br"></div>
                                                    <div class="henispost-tc"></div>
                                                    <div class="henispost-bc"></div>
                                                    <div class="henispost-cl"></div>
                                                    <div class="henispost-cr"></div>
                                                    <div class="henispost-cc"></div>
                                                    <div class="henispost-body">
                                                        <div class="henispost-inner henisarticle">
                                                            <h2 class="henispostheader"><?php echo $titre; ?></h2><br /><br />
                                                            <div class="henispostcontent">
                                                                <div class="aligncenter">
                                                                    <table>
                                                                        <tbody>
                                                                            <tr>
                                                                                <td>
                                                                                    <div id="container">


                                                                                        <form id="form1" name="formulaire" action="act_participants.php" method="post">	

                                                                                            <fieldset>
                                                                                                <p class="first">
                                                                                                    <label for="name">Nom <span style="color: red">*</span></label>
                                                                                                    <div style="color: tomato" id="nom"></div>
                                                                                                    <input type="text" name="nom" value="<?php echo $nom; ?>" />

                                                                                                </p>


                                                                                                <p>
                                                                                                    <label for="email">E-mail <span style="color: red">*</span></label>
                                                                                                    <div style="color: tomato" id="mail"></div>
                                                                                                    <input type="text" name="mail" value="<?php echo $mail; ?>" />
                                                                                                </p>


                                                                                                <p class="first">
                                                                                                    <label for="name">Institution <span style="color: red">*</span></label>
                                                                                                    <div style="color: tomato" id="institution"></div>
                                                                                                    <input type="text" name="institution" value="<?php echo $institution; ?>" />
                                                                                                </p>

                                                                                                <p class="first">
                                                                                                    <label for="name">Système d'exploitation utilisé <span style="color: #0092ef">*</span>
                                                                                                        <select name="se">
                                                                                                            <option value="OS X" <?php if ($se == 'OS X') echo 'selected'; ?> > OS X </option>
                                                                                                            <option value="Windows 32" <?php if ($se == 'Windows 32') echo 'selected'; ?> > Windows (32 bits) </option>
                                                                                                            <option value="Windows 64" <?php if ($se == 'Windows 64') echo 'selected'; ?> > Windows (64 bits) </option>
                                                                                                            <option value="Ubuntu 32" <?php if ($se == 'Ubuntu 32') echo 'selected'; ?> > Ubuntu (32 bits) </option>
                                                                                                            <option value="Ubuntu 64" <?php if ($se == 'Windows 64') echo 'selected'; ?> > Ubuntu (64 bits) </option>
                                                                                                            <option value="Autres" <?php if ($se == 'Autres') echo 'selected'; ?> > Autres </option>


                                                                                                        </select>
                                                                                                    </label>
                                                                                                </p>




                                                                                                <p>
                                                                                                    <label for="adresse">Adresse personnele</label>
                                                                                                    <textarea name="adresse" cols="30" rows="5"><?php echo $adresse; ?></textarea>
                                                                                                </p>




                                                                                            </fieldset>
                                                                                            <fieldset>

                                                                                                <p class="first">
                                                                                                    <label for="name">Prénom <span style="color: red">*</span></label>
                                                                                                    <div style="color: tomato" id="prenom"></div>
                                                                                                    <input type="text" name="prenom" value="<?php echo $prenom; ?>" />
                                                                                                </p>

                                                                                                <p>
                                                                                                    <label for="web">Téléphone <span style="color: red">*</span></label>
                                                                                                    <div style="color: tomato" id="tel"></div>
                                                                                                    <input type="text" name="tel" value="<?php echo $tel; ?>" />
                                                                                                </p>

                                                                                                <p class="first">
                                                                                                    <label for="name">Fonction <span style="color: red">*</span></label>
                                                                                                    <div style="color: tomato" id="fonction"></div>
                                                                                                    <input type="text" name="fonction"value="<?php echo $fonction; ?>"  />
                                                                                                </p>

                                                                                                <p class="first">
                                                                                                    <label for="name">Laboratoire de recherche</label>
                                                                                                    <input type="text" name="labo" id="labo" size="30" value="<?php echo $labo; ?>" />
                                                                                                </p>

                                                                                                <p class="first">														
                                                                                                    <label>1<sup>er</sup> Workshop ISIMG sur android</label>
                                                                                                    <label><input type="radio" name="premier" value="Non" <?php if ($premier == 'Non') echo 'checked'; ?> />Non, je n'ai pas assisté<br /></label> 
                                                                                                    <label><input type="radio" name="premier" value="Oui" <?php if ($premier == 'Oui') echo 'checked'; ?> />Oui, j'ai assisté</label>   

                                                                                                </p>
                                                                                                <br />
                                                                                                <p class="first">														
                                                                                                    <label>Mode de payement</label>
                                                                                                    <label><input type="radio" name="payement" value="Bon de commande" <?php if ($payement == 'Bon de commande') echo 'checked'; ?> />Bon de commande<br /></label> 
                                                                                                    <label><input type="radio" name="payement" value="Virement" <?php if ($payement == 'Virement') echo 'checked'; ?> />Virement<br /></label> 
                                                                                                    <label><input type="radio" name="payement" value="Chèque ou espèce" <?php if ($payement == 'Chèque ou espèce') echo 'checked'; ?> />Chèque ou espèce</label>   

                                                                                                </p>




                                                                                                <input type="hidden" name="id" value="<?php echo $id; ?>" />





                                                                                            </fieldset>


                                                                                            <p class="submit"><button type="submit" id="envoyer" onclick="return verif_formulaire(document.formulaire.mail)"><?php echo $bouton; ?></button></p>		


                                                                                        </form>

                                                                                    </div>            </td>
                                                                            </tr>
                                                                        </tbody>
                                                                    </table>
                                                                </div>
                                                            </div>
                                                            <div class="cleared"></div>
                                                        </div>
                                                        <div class="cleared"></div>
                                                    </div>
                                                </div>
                                                <div class="cleared"></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="cleared"></div>
                                    <div class="cleared"></div>
                                </div>
                            </div>
                            <div class="henisfooter">
                                <div class="henisfooter-t"></div>
                                <div class="henisfooter-b"></div>
                                <div class="henisfooter-body">
                                    <div class="henisfooter-text">
                                        <div class="cleared"></div>
                                        <p class="henispage-footer">Auteur : <a href="http://www.isimg.rnu.tn/fra/profil/heni_saber">henis</a>.</p>
                                    </div>
                                    <div class="cleared"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </body>
        </html>
        <?php
    }
}
?>